package org.example.web.controller;

import org.example.web.domain.Dept;
import org.example.web.domain.Result;
import org.example.web.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;

    /**
     * 查询所有部门
     * @return
     */
    @GetMapping
    public Result selectAllDept(){
        List<Dept> dept = deptService.selectAllDept();
        return Result.success(dept);
    }

    /**
     * 根据id删除部门
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable String id){
        deptService.deleteById(id);
        return Result.success();
    }

    /**
     * 新增员工
     * @param dept
     * @return
     */
    @PostMapping
    public Result insertDept(@RequestBody Dept dept){
        deptService.insertDept(dept);
        return Result.success();
    }

    /**
     * 根据id查询员工
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result selectById(@PathVariable String id){
        Dept dept = deptService.selectById(id);
        return Result.success(dept);
    }

    /**
     * 修改部门
     * @param dept
     * @return
     */
    @PutMapping
    public Result updateDept(@RequestBody Dept dept){
        deptService.updateDept(dept);
        return Result.success();
    }
}
